from django.contrib.auth.models import AbstractUser
from django.db import models
from datetime import datetime

# Create your models here.


class User(AbstractUser):
    nickname = models.CharField(max_length=20, null=True, verbose_name="昵称")
    mobile = models.CharField(max_length=15, unique=True, verbose_name="手机号")
    avatar = models.ImageField(upload_to="avatar", default='avatar/default.png', null=True, verbose_name="头像")
    wxchat = models.CharField(max_length=100, null=True, unique=True, verbose_name="微信账号")
    alipay = models.CharField(max_length=100, null=True, unique=True, verbose_name="支付宝账号")
    qq_number = models.CharField(max_length=11, null=True, unique=True, verbose_name="QQ号")

    expire_time = models.DateTimeField(default=datetime.now(), verbose_name='用户当前充值的到期时间')
    is_expire = models.BooleanField(default=True, verbose_name='用户会员是否到期')
    is_first = models.BooleanField(default=False, verbose_name='用户是否是第一个充值会员')

    user_type_choices = [
        (0, '普通用户'),
        (1, 'VIP'),
    ]
    user_type = models.IntegerField(choices=user_type_choices, default=0, verbose_name='用户类型')

    class Meta:
        # 自定义表名
        db_table = "rr_users"
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.nickname if self.nickname else self.username

    @property
    def user_type_name(self):
        return self.get_user_type_display()
